package top.hencter.weibo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 获取 navigation 对象
        final NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_container);
        // 获取 BottomNavigationView 对象，并添加时间监听
        BottomNavigationView bottomNavigationView = findViewById(R.id.navigation_header_container);
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @SuppressLint("NonConstantResourceId")
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.index:
                        navController.navigate(R.id.indexFragment);
                        break;
                    case R.id.video:
                        navController.navigate(R.id.videoFragment);
                        break;
                    case R.id.find:
                        navController.navigate(R.id.findFragment);
                        break;
                    case R.id.message:
                        navController.navigate(R.id.messageFragment);
                        break;
                    case R.id.user:
                        navController.navigate(R.id.userFragment);
                        break;
                    default:
                        break;
                }
                return true;
            }
        });

    }
}